#define _CRT_SECURE_NO_WANINGS 1
#pragma warning(disable: 4996)
int diverse(struct TreeNode* root1)
{
    if (root1 == NULL)
    {
        return 0;
    }
    return fmax(diverse(root1->left), diverse(root1->right)) + 1;
}
void diameter(struct TreeNode* root1, int* max)
{
    if (root1 == NULL)
    {
        return;
    }
    int d = diverse(root1->left) + diverse(root1->right);
    if (d > (*max))
    {
        *max = d;
    }
    diameter(root1->left, max);
    diameter(root1->right, max);
}
int diameterOfBinaryTree(struct TreeNode* root) {
    if (root->left == NULL && root->right == NULL)
    {
        return 0;
    }
    int max = 0;
    diameter(root, &max);
    return max;
}